package com.app.acitivty;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.app.activity.R;
import com.app.components.TopMenu;
import com.app.data.InnItem;
import com.app.data.LineItem;
import com.app.data.ScenicItem;
import com.app.data.YouhuiItem;
import com.app.service.HttpCallBack;
import com.app.service.LineService;
import com.app.service.adapter.LineAdapter;
import com.app.utils.ActivityTools;
import com.app.utils.GlobalConstants;

public class ScenicSearchListActivity extends Activity implements HttpCallBack,OnItemClickListener {

	private ArrayList<HashMap<String, String>> mScencListItems = null;

	private String[] mColumnNames = { "scenicIcon", "senicName", "senicPrice",
			"senicIntro", "senicSubject" };

	private int[] mViewIds = { R.id.imgScenicIcon, R.id.tvSenicName,
			R.id.tvSenicPrice, R.id.tvSenicIntro, R.id.tvSenicSubject };

	private ListView lvSceniclist;
	private ArrayList<LineItem> lines;
	private Button btnFootSearch;

	private LinearLayout linearLayout;

	ProgressDialog progressDialog;
	private void initView() {
		lvSceniclist = (ListView) findViewById(R.id.lvScenicList);	
		btnFootSearch=(Button) findViewById(R.id.btnSearch);

	}

	@SuppressWarnings("rawtypes")
	public static HashMap addItem(ScenicItem item) {
		HashMap<Object, Object> map = new HashMap<Object, Object>();
		map.put("scenicIcon", item.getScenicIcon());
		map.put("senicName", item.getSenicName());
		map.put("senicPrice", item.getSenicPrice());
		map.put("senicIntro", item.getSenicIntro());
		map.put("senicSubject", item.getSenicSubject());
		return map;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.scenic_search_list);
		
		initView();
		btnFootSearch.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				ActivityTools.gotoActivity(ScenicSearchListActivity.this,
						ScenicScheduledActivity.class);

			}
		});
		TopMenu topMenu = new TopMenu(this, "门票", new OnClickListener() {

			@Override
			public void onClick(View v) {
				ScenicSearchListActivity.this.finish();
				// // 跳转到预定页面
				// ActivityTools.gotoActivity(ScenicListActivity.this,
				// ScenicScheduledActivity.class);
			}
		}, R.drawable.top_button_unselect, R.drawable.top_button_selected,
				"景点列表");
		topMenu.onCreate();
		
	
		mScencListItems = new ArrayList<HashMap<String, String>>();

		progressDialog = new ProgressDialog(this);
		progressDialog.setTitle("提示");
		progressDialog.setMessage("读取数据中...");
		progressDialog.setCancelable(false);
		progressDialog.setIndeterminate(true);
		progressDialog.show();
//		for (int i = 0; i < 7; i++) {
//			ScenicItem si = new ScenicItem();
//			si.setScenicIcon(R.drawable.scen_logo);
//			si.setSenicName("丽江虎跳峡");
//			si.setSenicPrice("￥133起");
//			si.setSenicIntro("虎跳峡,中国最深的峡谷之一，在云南省玉龙纳西族自治县...");
//			si.setSenicSubject("主题：生态旅游  休闲  生态旅游");
//			mScencListItems.add(addItem(si));
//		}
//
//		ListAdapter la = new SimpleAdapter(this, mScencListItems,
//				R.layout.scenic_list_item, mColumnNames, mViewIds);
//	
		LineService lineService = new LineService(this);
		lineService.execute("");
		//lvSceniclist.setAdapter(la);
//		lvSceniclist.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
//					long arg3) {
//				ActivityTools.gotoActivity(ScenicSearchListActivity.this, ScenicDetailActivity.class);
//				
//			}
//		});

	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
		// TODO Auto-generated method stub
		System.out.println("itemClick");
		LineItem item = lines.get(position);
		GlobalConstants.getInstance().setLineitem(item);
		
		Intent intent = new Intent(this, LineDetailActivity.class);
		startActivity(intent);
	}
	
	@Override
	public void hotelFinishLoad(int code, ArrayList<InnItem> list) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void lineFinishLoad(int code, ArrayList<LineItem> list) {
		if (code == 0) {
			lines = list;
			LineAdapter adapter = new LineAdapter(this, list);
			lvSceniclist.setAdapter(adapter);
			lvSceniclist.setOnItemClickListener(this);
		}
		progressDialog.dismiss();
	}

	@Override
	public void ticketFinishLoad(int code, ArrayList<ScenicItem> list) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void youhuiFinishLoad(int code, ArrayList<YouhuiItem> list) {
		// TODO Auto-generated method stub
		
	}

}
